package com.bw.educate.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bw.educate.common.idwork.IdWorker;
import com.bw.educate.common.order.ReqEduOrder;
import com.bw.educate.entity.EduCourseBase;
import com.bw.educate.entity.EduOrder;
import com.bw.educate.mapper.EduOrderMapper;
import com.bw.educate.service.IEduOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 在线教育-五组
 * @since 2020-08-13
 */
@Service
public class EduOrderServiceImpl extends ServiceImpl<EduOrderMapper, EduOrder> implements IEduOrderService {

    @Autowired
    private EduOrderMapper eduOrderMapper;

    @Autowired
    private IdWorker idWorker;


    @Override
    public void addOrder(Long uid, EduCourseBase courseId) {

        EduOrder eduOrder = new EduOrder();
        eduOrder.setCid(courseId.getId());
        eduOrder.setSuid(uid);
        eduOrder.setCode(String.valueOf(idWorker.nextId()));
        eduOrder.setCreateTime(new Date());
        eduOrder.setPrice(courseId.getPrice());
        eduOrder.setStatus(0);

        eduOrderMapper.insert(eduOrder);
    }

    @Override
    public List<ReqEduOrder> listOrder() {

        return eduOrderMapper.listOrder();
    }
}
